<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<title>二级分类</title>
	</head>
	<body>
		<h1>类别信息展示</h1>
		<a href='./add.php'>继续添加父类</a><br><br>
		<a href="main_menu.php">不需要添加子类</a>

		<?php 
			//1. 连接数据库，并判断
				$link = mysqli_connect("localhost","root","") or die("数据库连接失败！");
			
			//2. 设置字符集
				mysqli_set_charset($link,"utf8");
				
			//3. 选择数据库
				mysqli_select_db($link,"bbs");
				
			//4. 定义sql语句，并发送执行
				$sql = "select *,concat(path,'-',id) as npath from type order by npath";
				$result = mysqli_query($link,$sql);
				
			//5. 判断
				if($result && mysqli_num_rows($result)>0){
					
					//解析结果集
					while($rows = mysqli_fetch_assoc($result)){
						
						//显示类别信息
						if($rows['pid']==0){
							echo "<h2><img src='./dirfirst.gif'/>{$rows['name']} <a href='./addChild.php?fname={$rows['name']}&fid={$rows['id']}'>添加子类别</a></h2>";
						}else{
							echo "<h3><img src='./dirsecond.gif'/>{$rows['name']}</h3>";
						}
						
					}
					
				}

		?>
	</body>
</html>